package com.kuang.singleton;

//单例模式的学习
//懒汉式
public class SingletonDemo02 {
    //1.私有化构造器
    private SingletonDemo02() {
    }
    //2。类初始化的时候，不立即这个对象
    private static SingletonDemo02 instance ;
    //3.提供获取该对象的方法，
    public static synchronized SingletonDemo02 getSingletonDemo02(){
        if (instance==null){
            instance = new SingletonDemo02();
        }
        return instance;
    }
}


class SingletonDemo02Test{
    public static void main(String[] args) {
        SingletonDemo01 instance1 = SingletonDemo01.getSingletonDemo01();
        SingletonDemo01 instance2 = SingletonDemo01.getSingletonDemo01();

        System.out.println(instance1==instance2);//true
    }
}

